DEFINITION MODULE DialogMgr;    (* Christoph Fleischer 06.02.85 *)
                                (* MacIntosh Toolbox Dialog Manager Routines *)
                                (* last modification   01.07.85 fxk*)
FROM SYSTEM IMPORT ADDRESS;
FROM MacBase IMPORT LongInt,Handle,StrPtr;
FROM WindowMgr IMPORT WindowPtr,WindowRecord;
FROM EventMgr IMPORT EventRecord;
FROM TextEdit IMPORT TEHandle;
FROM QuickDraw IMPORT Rect;

EXPORT QUALIFIED
  UserItem,CtrlItem,BtnCtrl,ChkCtrl,RadCtrl,ResCtrl,StatText,EditText,IconItem,PicItem,ItemDisable,OK,Cancel,
  DialogPtr,DialogPeek,DialogRecord,DialogTHndl,DialogTPtr,DialogTemplate,StageList,AlertTHndl,AlertTPtr,
  AlertTemplate,RestartProcPtr,FilterProcPtr,SoundNumber,ErrorProcPtr,
  InitDialogs,GetNewDialog,NewDialog,IsDialogEvent,DialogSelect,ModalDialog,DrawDialog,CloseDialog,
  DisposDialog,Alert,StopAlert,NoteAlert,CautionAlert,CouldAlert,FreeAlert,CouldDialog,FreeDialog,ParamText,
  ErrorSound,GetDItem,SetDItem,SetIText,GetIText,SelIText,DlgCut,DlgPaste,DlgCopy;

CONST
  UserItem    = 0;
  CtrlItem    = 4;
  BtnCtrl     = 0;              (* Low two bits specify what kind of control *)
  ChkCtrl     = 1;
  RadCtrl     = 2;
  ResCtrl     = 3;

  StatText    = 8;              (* Static text    *)
  EditText    = 16;             (* Editable text  *)
  IconItem    = 32;             (* Icon item      *)
  PicItem     = 64;             (* Picture item   *)
  ItemDisable = 128;            (* Disable item if set *)

  OK          = 1;              (* OK button is first by convention *)
  Cancel      = 2;              (* Cancel button is second by convention *)

TYPE
  DialogPtr    = WindowPtr;
  DialogPeek   = POINTER TO DialogRecord;
  DialogRecord = RECORD
                   window:      WindowRecord;
                   Items:       Handle;
                   textH:       TEHandle;
                   EditField:   INTEGER;
                   EditOpen:    INTEGER;
                   ADefItem:    INTEGER;
                 END;

  DialogTHndl    = POINTER TO DialogTPtr;
  DialogTPtr     = POINTER TO DialogTemplate;
  DialogTemplate = RECORD
                     boundsRect:  Rect;
                     procID:      INTEGER;
                     visible:     BOOLEAN;
                     filler1:     BOOLEAN;
                     goAwayFlag:  BOOLEAN;
                     filler2:     BOOLEAN;
                     refCon:      LongInt;
                     ItemsID:     INTEGER;
                     title:       ARRAY[0..255] OF CHAR;
                   END;

  StageList      = BITSET;      (* PACKED ARRAY [1..4] OF RECORD
                                     boldItem:  [0..1];
                                     boxDrawn:  BOOLEAN;
                                     sound:     [0..3];
                                   END;                     *)

  AlertTHndl    = POINTER TO AlertTPtr;
  AlertTPtr     = POINTER TO AlertTemplate;
  AlertTemplate = RECORD
                    boundsRect:  Rect;
                    itemsID:     INTEGER;
                    stages:      StageList;
                  END;

  RestartProcPtr = ADDRESS;
  FilterProcPtr  = ADDRESS;(* PROCEDURE(DialogPtr,VAR EventRecord,VAR INTEGER): BOOLEAN;*)
  SoundNumber    = [0..3];
  ErrorProcPtr   = ADDRESS;


PROCEDURE InitDialogs(restartProc: RestartProcPtr);               (*INLINE $A97B*)
PROCEDURE GetNewDialog(dialogID: INTEGER;
                       wStorage: ADDRESS;
                       behind:  WindowPtr): DialogPtr;            (*INLINE $A97C*)
PROCEDURE NewDialog(wStorage:       ADDRESS;
                    VAR boundsRect: Rect;
                    title:          StrPtr;
                    visible:        BOOLEAN;
                    theProc:        INTEGER;
                    behind:         WindowPtr;
                    goAwayFlag:     BOOLEAN;
                    refCon:         LongInt;
                    itmLstHndl:     Handle): DialogPtr;           (*INLINE $A97D*)
PROCEDURE IsDialogEvent(VAR event:   EventRecord): BOOLEAN;       (*INLINE $A97F*)
PROCEDURE DialogSelect (VAR event:   EventRecord;
                       VAR theDialog:  DialogPtr;
                       VAR itemHit: INTEGER): BOOLEAN;            (*INLINE $A980*)
PROCEDURE ModalDialog( filterProc: FilterProcPtr; VAR itemHit: INTEGER);
                                                                  (*INLINE $A991*)
PROCEDURE DrawDialog(dialog: DialogPtr);                          (*INLINE $A981*)
PROCEDURE CloseDialog(dialog: DialogPtr);                         (*INLINE $A982*)
PROCEDURE DisposDialog(dialog: DialogPtr);                        (*INLINE $A983*)
PROCEDURE Alert(alertID:     INTEGER;
                filterProc:  FilterProcPtr): INTEGER;             (*INLINE $A985*)
PROCEDURE StopAlert(alertID:     INTEGER;
                    filterProc:  FilterProcPtr): INTEGER;         (*INLINE $A986*)
PROCEDURE NoteAlert(alertID:     INTEGER;
                    filterProc:  FilterProcPtr): INTEGER;         (*INLINE $A987*)
PROCEDURE CautionAlert(alertID:     INTEGER;
                       filterProc:  FilterProcPtr): INTEGER;      (*INLINE $A988*)
PROCEDURE CouldAlert(alertID:  INTEGER);                          (*INLINE $A989*)
PROCEDURE FreeAlert(alertID:   INTEGER);                          (*INLINE $A98A*)
PROCEDURE CouldDialog(DlgID:  INTEGER);                           (*INLINE $A979*)
PROCEDURE FreeDialog(DlgID:   INTEGER);                           (*INLINE $A97A*)
PROCEDURE ParamText(cite0, cite1, cite2, cite3:  StrPtr);     (*INLINE $A98B*)
PROCEDURE ErrorSound(sound: ErrorProcPtr);                        (*INLINE $A98C*)
PROCEDURE GetDItem(dialog:         DialogPtr;
                   itemNo:         INTEGER;
                   VAR kind:       INTEGER;
                   VAR item:       Handle;
                   VAR box:        Rect);                         (*INLINE $A98D*)
PROCEDURE SetDItem(dialog:         DialogPtr;
                   itemNo:         INTEGER;
                   kind:           INTEGER;
                   item:           Handle;
                   VAR box:        Rect);                         (*INLINE $A98E*)
PROCEDURE SetIText(item:       Handle; text:   StrPtr);                           (*INLINE $A98F*)
PROCEDURE GetIText(item:       Handle; text:   StrPtr);                           (*INLINE $A990*)
PROCEDURE SelIText(dialog:   DialogPtr;
                   itemNo:   INTEGER;
                   startSel, endSel: INTEGER );                   (*INLINE $A97E*)

(*********** These procedures are not yet implemented ****************)

PROCEDURE DlgCut(dialog: DialogPtr);
PROCEDURE DlgPaste(dialog: DialogPtr);
PROCEDURE DlgCopy(dialog: DialogPtr);

END DialogMgr.
